package Entity;

import java.sql.ResultSet;
import java.util.ArrayList;

import Control.MySQLController;

public class Workshop_WorkshopCategory {
	//Attributes
	private String categoryCode;
	private String description;

	//Getters and Setters
	public String getCategoryCode() {
		return categoryCode;
	}

	public void setCategoryCode(String categoryCode) {
		this.categoryCode = categoryCode;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	//Constructors
	public Workshop_WorkshopCategory(){}
	

	public Workshop_WorkshopCategory(String categoryCode){
		this.categoryCode = categoryCode;
	}
	
	public Workshop_WorkshopCategory(String categoryCode, String description){
		this.categoryCode = categoryCode;
		this.description = description;
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	public static ArrayList<Workshop_WorkshopCategory> retrieveAllCategory(){
		ArrayList<Workshop_WorkshopCategory> categoryList = new ArrayList<Workshop_WorkshopCategory>();
		
		ResultSet rs = null;
		MySQLController db = new MySQLController();
		db.getConnection();
		String sql = "SELECT * FROM ooadpj.category";
		rs = db.readRequest(sql);
		try{
			while(rs.next()){
				Workshop_WorkshopCategory category = new Workshop_WorkshopCategory();
				category.setCategoryCode(rs.getString("category_code"));
				category.setDescription(rs.getString("description"));
				categoryList.add(category);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		finally{
			db.terminate();
		}
		return categoryList;
	}
	public boolean retrieveACategory(){
		boolean success = false;
		ResultSet rs = null;
		MySQLController db = new MySQLController();
		db.getConnection();
		String sql = "SELECT * FROM ooadpj.category WHERE category_code = '" + categoryCode + "'";
		rs = db.readRequest(sql);
		try{
			while(rs.next()){
				description = rs.getString("description");
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		finally{
			db.terminate();
		}
		return success;
	}
}
